<template>
    <div class="promotionOrder">
      <div class="container">
        <el-form :model="proOrderForm" label-width="100px" ref="proOrderRefs" class="proOrderCls">
          <el-form-item label="用户类型：">
            <el-radio-group v-model="proOrderForm.type" size="small" @change="getExtensionList('1')">
              <el-radio-button :label="-99">全部</el-radio-button>
              <el-radio-button :label="0">一级推广人</el-radio-button>
              <el-radio-button :label="1">二级推广人</el-radio-button>
            </el-radio-group>
          </el-form-item>
          <el-row>
            <el-col v-bind="grid">
              <el-form-item label="订单号：" class="search-select">
                <el-input v-model="proOrderForm.keyword" placeholder="请输入订单号" size="small" clearable>
                  <el-button slot="append" icon="el-icon-search" size="small" @click="getExtensionList('1')"></el-button>
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <el-table
        key="order"
        v-loading="spreadLoading"
        :data="spreadData"
        style="width: 100%"
        size="mini"
        class="table"
        highlight-current-row
      >
        <el-table-column
          prop="orderNo"
          label="订单ID"
          min-width="130"
        />
        <el-table-column
          label="用户信息"
          min-width="220"
        >
          <template slot-scope="{ row }">
            <span>{{ row.user.nickName }}<el-divider direction="vertical" v-if="row.user.mobile"></el-divider>{{ row.user.mobile }}<el-divider direction="vertical" v-if="row.user.realName"></el-divider>{{ row.user.realName }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="时间"
          min-width="150"
        >
          <template slot-scope="{ row }">
            <span>{{ row.createDateUTC | uctTimeFileter }}</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable
          label="返佣金额"
          min-width="120"
        >
          <template slot-scope="{ row }">
            <span>{{ row.agent_Commission_Price | NumFormat }}</span>
          </template>
        </el-table-column>
      </el-table>
      <div class="spreadBox">
        <pagination
          v-show="pagination.total > 0"
          :total="pagination.total"
          :page.sync="pagination.page"
          :limit.sync="pagination.limit"
          :page-sizes="[10, 20, 30, 50]"
          @pagination="spreadChange"
        />
      </div>
    </div>
</template>

<script>
  import {
    getExtensionListApi
  } from '@/api/agent';

  export default {
    name: "index",
    props: {
      id: {
        type: [Number, String],
        default: 0
      }
    },
    data() {
      return {
        grid: {
          xl: 10,
          lg: 10,
          md: 10,
          sm: 12,
          xs: 24
        },
        proOrderForm: {
          keyword: '',
          type: -99
        },
        spreadLoading: false,
        spreadData: [],
        pagination: {
          page: 1,
          limit: 10,
          total: 0
        }
      };
    },
    mounted() {
      this.getExtensionList();
    },
    methods: {
      /**
       * 代理商客户推广订单
       * @param num
       */
      getExtensionList(num) {
        this.$set(this, 'spreadLoading', true);
        getExtensionListApi(this.id, {
          pageNumber: num ? num : this.pagination.page,
          pageSize: this.pagination.limit,
          orderBy: 'signDateUTC desc',
          keyword: this.proOrderForm.keyword,
          type: this.proOrderForm.type === -99 ? -1 : this.proOrderForm.type
        }).then(res => {
          console.log('代理商客户推广订单', res);
          this.$set(this, 'spreadData', res.data);
          this.$set(this.pagination, 'total', res.head.totalCount);
          this.$set(this, 'spreadLoading', false);
        }).catch(() => {
          this.$set(this, 'spreadData', []);
          this.$set(this.pagination, 'total', 0);
          this.$set(this, 'spreadLoading', false);
        });
      },
      spreadChange(spread) {
        this.$set(this.pagination, 'limit', spread.limit);
        this.getExtensionList('1');
      }
    }
  }
</script>

<style lang="scss" scoped>
  .spreadBox {
    ::v-deep .pagination-container {
      margin-top: 25px;
      padding: 0 0;
      .el-pagination {
        display: flex;
        justify-content: flex-end;
      }
    }
  }
</style>
